function _toConsumableArray(t) {
  if (Array.isArray(t)) {
    for (var e = 0, a = Array(t.length); e < t.length; e++) a[e] = t[e];
    return a;
  }
  return Array.from(t);
}

var g, pages, app = getApp(),
  page = app.page,
  request = app.util.request,
  route = app.route,
  _tools = require("../../utils/tools"),
  toast = app.toast;

function getList() {
  request({
    url: "MyTeamList",
    data: {
      user_id: g.data.uid || (app.userInfo.id || wx.getStorageSync("userInfo").id),
      page: pages,
      number: app.config.fx_number,
      type: g.data.typeList[g.data.currentType].value,
      keywords: g.data.keyword || ''
    },
    success: function (t) {
      var e = g.data.list,
        a = t.list;
      e && 1 != pages && (a = [].concat(_toConsumableArray(e), _toConsumableArray(a))),
        g.setData({
          list: a,
          avatar: t.avatar,
          num: t.num,
          today_num: t.reg_num
        }), g.data.fxset || g.setData({
          fxset: wx.getStorageSync("fxset")
        }), a.length && pages * app.config.fx_number >= t.num && g.setData({
          isLoad: !0
        }), wx.stopPullDownRefresh();
    }
  });
}
page({
  data: {
    useInfo: "",
    typeList: [{
        name: "全部",
        value: '0'
      },
      {
        name: "一级代理",
        value: "1"
      },
      {
        name: "二级代理",
        value: "2"
      }
    ],
    currentType: 0,
    no_laws: app.srcRoot + "no_law.png",
    isLoad: !1,
    uid: "",
    title: "",
    keyword: '',
    num: 0,
    today_num: 0,
    avatar: ''
  },
  onLoad: function (t) {
    g = this;
    g.setData({
      uid: t.uid || '',
      title: t.nickname ? (t.nickname + '的团队') :"我的团队"
    })
    let userInfo = wx.getStorageSync("userInfo")
    if (userInfo) {
      request({
        url: "AddUsersLog",
        data: {
          user_id: userInfo.id,
          url: '/fenxiao/team/list',
          title: g.data.title
        },
        success: function (a) {}
      })
      request({
        url: "Openid",
        showLoading: !1,
        data: {
          user_id: g.data.userInfo.id
        },
        success: function (t) {
          wx.setStorageSync("userInfo", t)
          g.setData({
            userInfo: t
          })
        }
      })
    }
    pages = 1
    getList();
  },
  onUnload: function(){
    g.setData({
      uid: ''
    })
  },
  onReady: function () {
    var t = wx.getSystemInfoSync().screenWidth,
      e = .04 * t,
      t = (e * e + t * t / 4) / (2 * e);
    g.setData({
      style: "background: radial-gradient(circle at 50% " + (e - t) + "px, " + wx.getStorageSync("system").foot_color2 + " " + t + "px, rgba(0,0,0,0) " + t / 2 + "px);"
    }), (0, _tools.getNodeInfo)({
      id: "#top",
      success: function (t) {
        // return g.setData({
        //   top: t.bottom
        // });
      }
    });
  },
  onPullDownRefresh: function () {
    pages = 1, getList();
  },
  onReachBottom: function () {
    !g.data.isLoad && pages++ && getList();
  },
  keywordSearch: function () {
    pages = 1, getList();
  },
  input: function (a) {
    let keyword = a.detail.value;
    g.setData({
      keyword
    })
  },
  toPage: function (t) {
    var url = t.currentTarget.dataset.url;
    wx.navigateTo({
      url
    })
  },
  bindTypeChange: function (e) {
    g.setData({
      currentType: e.detail.value
    })
    pages = 1, getList();
  },
  goTeam: function (t) {
    if(g.data.uid){
      return false
    }
     let uid = t.currentTarget.dataset.uid;
     let nickname = t.currentTarget.dataset.nickname;
     wx.navigateTo({
       url: '/fenxiao/team/list?uid='+uid + "&nickname="+nickname,
     })
  },
});